﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using AdvancedDataGridView;
using YArchitech.Controls;
using YArchitech.DataModel;

namespace YArchitech.HVAC.PipeSetting
{
    //public partial class FrmPipeSetting : System.Windows.Forms.Form
    public partial class FrmPipeSetting : HYBaseForm
	{
		public FrmPipeSetting()
		{
			this.isInit = true;
			this.InitializeComponent();
			this.isInit = false;
		}

		public FrmPipeSetting(List<SystemTypeInfo> pipingTypeList) : this()
		{
			this.PipingTypeList = pipingTypeList;
			this.SetGridStyle();
		}

		private void FrmPipeSetting_Load(object sender, EventArgs e)
		{
			bool flag = true;
			int width = base.Width;
			int height = base.Height;
			int width2 = this.colSysType.Width;
			int width3 = this.colAbb.Width;
			int width4 = this.colPipeType.Width;
			int width5 = this.colLineColor.Width;
			int width6 = this.colLinePattern.Width;
			int width7 = this.colLineWeight.Width;
			int width8 = this.colPipingCategory.Width;
			int width9 = this.colPipingGroup.Width;
			try
			{
				string[] array = this.userSettingMgr.ReadPipeSettingInfo();
				if (array != null && array.Length == 10)
				{
					if (!string.IsNullOrEmpty(array[0]))
					{
						width = Convert.ToInt32(array[0]);
					}
					if (!string.IsNullOrEmpty(array[1]))
					{
						height = Convert.ToInt32(array[1]);
					}
					if (!string.IsNullOrEmpty(array[2]))
					{
						width2 = Convert.ToInt32(array[2]);
					}
					if (!string.IsNullOrEmpty(array[3]))
					{
						width3 = Convert.ToInt32(array[3]);
					}
					if (!string.IsNullOrEmpty(array[4]))
					{
						width4 = Convert.ToInt32(array[4]);
					}
					if (!string.IsNullOrEmpty(array[5]))
					{
						width5 = Convert.ToInt32(array[5]);
					}
					if (!string.IsNullOrEmpty(array[6]))
					{
						width6 = Convert.ToInt32(array[6]);
					}
					if (!string.IsNullOrEmpty(array[7]))
					{
						width7 = Convert.ToInt32(array[7]);
					}
					if (!string.IsNullOrEmpty(array[8]))
					{
						width8 = Convert.ToInt32(array[8]);
					}
					if (!string.IsNullOrEmpty(array[9]))
					{
						width9 = Convert.ToInt32(array[9]);
					}
				}
			}
			catch (Exception ex)
			{
				string message = ex.Message;
				flag = false;
			}
			if (flag)
			{
				base.Width = width;
				base.Height = height;
				this.colSysType.Width = width2;
				this.colAbb.Width = width3;
				this.colPipeType.Width = width4;
				this.colLineColor.Width = width5;
				this.colLinePattern.Width = width6;
				this.colLineWeight.Width = width7;
				this.colPipingCategory.Width = width8;
				this.colPipingGroup.Width = width9;
			}
			if (this.PipingTypeList == null)
			{
				return;
			}
			this.InitComboBox();
			this.RefreshTaskList();
			this.tvTaskList_SelectionChanged(null, null);
		}

		private void InitComboBox()
		{
			IList<string> linePatternName = PipeSettingManager.GetLinePatternName();
			IList<string> lineWeight = PipeSettingManager.GetLineWeight();
			IList<string> pipingClassify = PipeSettingManager.PipingClassify;
			IList<string> pipeTypeNames = PipeSettingManager.GetPipeTypeNames();
			this.InitComboBoxColumn(this.colLineWeight, lineWeight);
			this.colLineWeight.Items.Insert(0, "默认");
			this.InitComboBoxColumn(this.colLinePattern, linePatternName);
			this.colLinePattern.Items.Insert(0, "默认");
			this.InitComboBoxColumn(this.colPipeType, pipeTypeNames);
		}

		private void btnImportStd_Click(object sender, EventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = " xml files(*.xml)|*.xml|All files(*.*)|*.*";
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				try
				{
					SystemTypeXmlHelper systemTypeXmlHelper = new SystemTypeXmlHelper(openFileDialog.FileName);
					IList<string> standardStyle = systemTypeXmlHelper.GetStandardStyle();
					if (standardStyle == null || standardStyle.Count != 1)
					{
						throw new Exception();
					}
					string text = standardStyle.First<string>();
					if (!text.Equals(PipeSettingManager.CurProjectStyle))
					{
						throw new Exception();
					}
					string xpath = string.Format("styleNode[@name='{0}']/system[@name='{1}']/group", text, PipeSettingManager.SystemName);
					IDictionary<string, IList<SystemTypeInfo>> pipingTypeWithGroup = systemTypeXmlHelper.GetPipingTypeWithGroup(xpath);
					IDictionary<SystemTypeInfo, IList<SystemTypeInfo>> dictionary = new Dictionary<SystemTypeInfo, IList<SystemTypeInfo>>();
					IList<SystemTypeInfo> list = new List<SystemTypeInfo>();
					IEnumerator<string> enumerator = pipingTypeWithGroup.Keys.GetEnumerator();
					{
						while (enumerator.MoveNext())
						{
							string key = enumerator.Current;
							if ((from x in this.PipingTypeList
							where x.IsParent && x.SysType == key
							select x).FirstOrDefault<SystemTypeInfo>() == null)
							{
								IList<SystemTypeInfo> list2 = new List<SystemTypeInfo>();
								int sortIndex = (from x in this.PipingTypeList
								where x.IsParent
								select x).Count<SystemTypeInfo>();
								SystemTypeInfo systemTypeInfo = new SystemTypeInfo
								{
									IsParent = true,
									SortIndex = sortIndex,
									SysType = key
								};
								int num = 0;
								IEnumerator<SystemTypeInfo> enumerator2 = pipingTypeWithGroup[key].GetEnumerator();
								{
									while (enumerator2.MoveNext())
									{
										SystemTypeInfo item = enumerator2.Current;
										item.GroupName = key;
										item.SortIndex = num++;
										item.GroupSortIndex = systemTypeInfo.SortIndex;
										SystemTypeInfo systemTypeInfo2 = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => !x.IsParent && x.SysType == item.SysType);
										if (systemTypeInfo2 == null)
										{
											this.PipingTypeList.Add(item);
											if (!this.PipingTypeList.Contains(systemTypeInfo))
											{
												this.PipingTypeList.Add(systemTypeInfo);
											}
										}
										else if (systemTypeInfo2.SysCategory != item.SysCategory)
										{
											if (!this.IsLastInClassifyGroup(systemTypeInfo2))
											{
												if (PipeSettingManager.IsExsitCreatedPiping(new List<SystemTypeInfo>
												{
													systemTypeInfo2
												}))
												{
													list.Add(systemTypeInfo2);
												}
												else
												{
													list2.Add(item);
												}
											}
										}
										else
										{
											list2.Add(item);
										}
									}
								}
								if (list2.Count > 0)
								{
									dictionary.Add(systemTypeInfo, list2);
								}
							}
							else
							{
								IList<SystemTypeInfo> list3 = new List<SystemTypeInfo>();
								SystemTypeInfo key2 = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => x.IsParent && x.SysType == key);
								int num2 = -1;
								IEnumerator<SystemTypeInfo> enumerator2 = pipingTypeWithGroup[key].GetEnumerator();
								{
									while (enumerator2.MoveNext())
									{
										SystemTypeInfo item = enumerator2.Current;
										SystemTypeInfo systemTypeInfo2 = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => !x.IsParent && x.SysType == item.SysType);
										if (systemTypeInfo2 == null)
										{
											int sortIndex2 = (from x in this.PipingTypeList
											where !x.IsParent && x.GroupName == item.GroupName
											select x).Count<SystemTypeInfo>();
											item.SortIndex = sortIndex2;
											item.GroupSortIndex = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => !x.IsParent && x.GroupName == item.GroupName).GroupSortIndex;
											this.PipingTypeList.Add(item);
										}
										else
										{
											if (systemTypeInfo2.SysCategory != item.SysCategory)
											{
												if (this.IsLastInClassifyGroup(systemTypeInfo2))
												{
													continue;
												}
												if (PipeSettingManager.IsExsitCreatedPiping(new List<SystemTypeInfo>
												{
													systemTypeInfo2
												}))
												{
													list.Add(systemTypeInfo2);
													continue;
												}
											}
											if (systemTypeInfo2.GroupName != item.GroupName)
											{
												if (num2 == -1)
												{
													num2 = (from x in this.PipingTypeList
													where !x.IsParent && x.GroupName == item.GroupName
													select x).Count<SystemTypeInfo>();
												}
												item.SortIndex = num2++;
												item.GroupSortIndex = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => !x.IsParent && x.GroupName == item.GroupName).GroupSortIndex;
											}
											else
											{
												item.SortIndex = systemTypeInfo2.SortIndex;
												item.GroupSortIndex = systemTypeInfo2.GroupSortIndex;
											}
											list3.Add(item);
										}
									}
								}
								if (list3.Count > 0)
								{
									dictionary.Add(key2, list3);
								}
							}
						}
					}
                    if ((dictionary.Count<KeyValuePair<SystemTypeInfo, IList<SystemTypeInfo>>>() > 0 || list.Count > 0) && YJKMessageBox.Show("导入的系统类型与当前项目中系统类型名称冲突，是否替换当前项目中系统类型的设置。", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                    }
                    //{
                    //    FrmPipeSetting.<>c__DisplayClass7_3 <>c__DisplayClass7_4 = new FrmPipeSetting.<>c__DisplayClass7_3();
                    //    <>c__DisplayClass7_4.tmpItem = null;
                    //    <>c__DisplayClass7_4.groupItem = null;
                    //    foreach (SystemTypeInfo systemTypeInfo3 in dictionary.Keys)
                    //    {
                    //        if (!this.PipingTypeList.Contains(systemTypeInfo3))
                    //        {
                    //            this.PipingTypeList.Add(systemTypeInfo3);
                    //        }
                    //        IEnumerator<SystemTypeInfo> enumerator3 = dictionary[systemTypeInfo3].GetEnumerator();
                    //        {
                    //            while (enumerator3.MoveNext())
                    //            {
                    //                SystemTypeInfo item = enumerator3.Current;
                    //                <>c__DisplayClass7_4.tmpItem = (from x in this.PipingTypeList
                    //                where x.SysType == item.SysType && !x.IsParent
                    //                select x).FirstOrDefault<SystemTypeInfo>();
                    //                if (<>c__DisplayClass7_4.tmpItem != null)
                    //                {
                    //                    this.PipingTypeList.Remove(<>c__DisplayClass7_4.tmpItem);
                    //                    this.PipingTypeList.Add(item);
                    //                    IEnumerable<SystemTypeInfo> pipingTypeList = this.PipingTypeList;
                    //                    Func<SystemTypeInfo, bool> predicate;
                    //                    if ((predicate = <>c__DisplayClass7_4.<>9__10) == null)
                    //                    {
                    //                        predicate = (<>c__DisplayClass7_4.<>9__10 = ((SystemTypeInfo x) => !x.IsParent && x.GroupName == <>c__DisplayClass7_4.tmpItem.GroupName));
                    //                    }
                    //                    if (pipingTypeList.Where(predicate).Count<SystemTypeInfo>() <= 0)
                    //                    {
                    //                        FrmPipeSetting.<>c__DisplayClass7_3 <>c__DisplayClass7_6 = <>c__DisplayClass7_4;
                    //                        IEnumerable<SystemTypeInfo> pipingTypeList2 = this.PipingTypeList;
                    //                        Func<SystemTypeInfo, bool> predicate2;
                    //                        if ((predicate2 = <>c__DisplayClass7_4.<>9__11) == null)
                    //                        {
                    //                            predicate2 = (<>c__DisplayClass7_4.<>9__11 = ((SystemTypeInfo x) => x.IsParent && x.SysType == <>c__DisplayClass7_4.tmpItem.GroupName));
                    //                        }
                    //                        <>c__DisplayClass7_6.groupItem = pipingTypeList2.FirstOrDefault(predicate2);
                    //                        this.PipingTypeList.Remove(<>c__DisplayClass7_4.groupItem);
                    //                        IEnumerable<SystemTypeInfo> pipingTypeList3 = this.PipingTypeList;
                    //                        Func<SystemTypeInfo, bool> predicate3;
                    //                        if ((predicate3 = <>c__DisplayClass7_4.<>9__12) == null)
                    //                        {
                    //                            predicate3 = (<>c__DisplayClass7_4.<>9__12 = ((SystemTypeInfo x) => x.IsParent && x.SortIndex > <>c__DisplayClass7_4.groupItem.SortIndex));
                    //                        }
                    //                        IEnumerator<SystemTypeInfo> enumerator4 = ((IEnumerable<SystemTypeInfo>)pipingTypeList3.Where(predicate3).ToList<SystemTypeInfo>()).GetEnumerator();
                    //                        {
                    //                            while (enumerator4.MoveNext())
                    //                            {
                    //                                SystemTypeInfo gItem = enumerator4.Current;
                    //                                gItem.SortIndex--;
                    //                                foreach (SystemTypeInfo systemTypeInfo4 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
                    //                                where !x.IsParent && x.GroupName == gItem.SysType
                    //                                select x).ToList<SystemTypeInfo>()))
                    //                                {
                    //                                    systemTypeInfo4.GroupSortIndex = gItem.SortIndex;
                    //                                }
                    //                            }
                    //                        }
                    //                    }
                    //                }
                    //            }
                    //        }
                    //    }
                    //    if (list.Count > 0)
                    //    {
                    //        StringBuilder stringBuilder = new StringBuilder();
                    //        stringBuilder.Append("[");
                    //        foreach (SystemTypeInfo systemTypeInfo5 in list)
                    //        {
                    //            stringBuilder.Append(systemTypeInfo5.SysType);
                    //            stringBuilder.Append(",");
                    //        }
                    //        stringBuilder.Append("]");
                    //        stringBuilder.Remove(stringBuilder.Length - 2, 1);
                    //        YJKMessageBox.Show(string.Format("选定的系统类型{0}正在使用，因此不能修改系统名称或删除此系统！", stringBuilder.ToString()), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    //    }
                    //}
					this.RefreshTaskList();
				}
				catch
				{
					YJKMessageBox.Show("请导入正确的数据文件！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
			}
		}

		private void btnExportStd_Click(object sender, EventArgs e)
		{
			try
			{
				string fileName = "当前项目管道系统样式";
				this.SaveFileDialog(fileName);
			}
			catch (Exception)
			{
				YJKMessageBox.Show("导出标准失败！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}

		private void btnAddSystem_Click(object sender, EventArgs e)
		{
			try
			{
				string message = "请选择新建项！";
				if (this.tvTaskList.SelectedRows.Count <= 0)
				{
					YJKMessageBox.Show(message);
				}
				else
				{
					TreeGridNode owningNode = ((TreeGridCell)this.tvTaskList.SelectedRows[0].Cells[0]).OwningNode;
					if (owningNode == null)
					{
						YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					}
					else
					{
						SystemTypeInfo sysTypeInfo = owningNode.Tag as SystemTypeInfo;
						if (sysTypeInfo == null)
						{
							YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						else
						{
							SystemTypeInfo copyItem = null;
							if (sysTypeInfo.IsParent)
							{
								SystemTypeInfo systemTypeInfo = (from x in this.PipingTypeList
								where !x.IsParent && x.GroupName == sysTypeInfo.SysType
								orderby x.SortIndex
								select x).FirstOrDefault<SystemTypeInfo>();
								if (systemTypeInfo == null)
								{
									YJKMessageBox.Show("当前分组中无有效项！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
									return;
								}
								copyItem = systemTypeInfo.Clone();
							}
							else
							{
								copyItem = sysTypeInfo.Clone();
							}
							SystemTypeInfo copyItem2 = copyItem;
							//copyItem2.SysType++;
							IList<string> existNames = PipeSettingManager.GetExistNames(false, this.PipingTypeList);
							IList<string> existNames2 = PipeSettingManager.GetExistNames(true, this.PipingTypeList);
							FrmAddPiping frmAddPiping = new FrmAddPiping(copyItem, existNames);
							if (frmAddPiping.ShowDialog(this) == DialogResult.OK)
							{
								SystemTypeInfo systemTypeInfo2 = null;
								SystemTypeInfo newSubInfo = frmAddPiping.OutputInfo;
								if (newSubInfo != null)
								{
									if (existNames2.Contains(newSubInfo.GroupName))
									{
										newSubInfo.SortIndex = copyItem.SortIndex + 1;
										newSubInfo.IsParent = false;
										newSubInfo.GroupSortIndex = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => x.IsParent && x.SysType == newSubInfo.GroupName).SortIndex;
										foreach (SystemTypeInfo systemTypeInfo3 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
										where !x.IsParent && x.GroupName == newSubInfo.GroupName && x.SortIndex > copyItem.SortIndex
										select x).ToList<SystemTypeInfo>()))
										{
											systemTypeInfo3.SortIndex++;
										}
										this.PipingTypeList.Add(newSubInfo);
									}
									else
									{
										SystemTypeInfo srcGroupNode = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => x.IsParent && x.SysType == copyItem.GroupName);
										if (srcGroupNode == null)
										{
											throw new Exception("数据出错！");
										}
										systemTypeInfo2 = new SystemTypeInfo
										{
											IsParent = true,
											SortIndex = srcGroupNode.SortIndex + 1,
											SysType = newSubInfo.GroupName
										};
                                        IEnumerator<SystemTypeInfo> enumerator = ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
                                                                                                                where x.IsParent && x.SortIndex > srcGroupNode.SortIndex
                                                                                                                select x).ToList<SystemTypeInfo>()).GetEnumerator();
										{
											while (enumerator.MoveNext())
											{
												SystemTypeInfo item = enumerator.Current;
												item.SortIndex++;
												foreach (SystemTypeInfo systemTypeInfo4 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
												where !x.IsParent && x.GroupName == item.SysType
												select x).ToList<SystemTypeInfo>()))
												{
													systemTypeInfo4.GroupSortIndex = item.SortIndex;
												}
											}
										}
										this.PipingTypeList.Add(systemTypeInfo2);
										newSubInfo.IsParent = false;
										newSubInfo.SortIndex = 0;
										newSubInfo.GroupSortIndex = systemTypeInfo2.SortIndex;
										this.PipingTypeList.Add(newSubInfo);
									}
									this.RefreshTaskList();
									this.SelectedRow(newSubInfo);
								}
							}
						}
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("新建系统失败！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}

		private void btnAddSystem_Click1(object sender, EventArgs e)
		{
			try
			{
				string message = "请选择新建项！";
				if (this.tvTaskList.SelectedRows.Count <= 0)
				{
					YJKMessageBox.Show(message);
				}
				else
				{
					TreeGridNode owningNode = ((TreeGridCell)this.tvTaskList.SelectedRows[0].Cells[0]).OwningNode;
					if (owningNode == null)
					{
						YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					}
					else
					{
						SystemTypeInfo sysTypeInfo = owningNode.Tag as SystemTypeInfo;
						if (sysTypeInfo == null)
						{
							YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						else
						{
							IList<string> existNames = PipeSettingManager.GetExistNames(sysTypeInfo.IsParent, this.PipingTypeList);
							FrmAddSysType frmAddSysType = new FrmAddSysType(sysTypeInfo, existNames);
							if (frmAddSysType.ShowDialog(this) == DialogResult.OK)
							{
								if (!string.IsNullOrEmpty(frmAddSysType.NewName))
								{
									SystemTypeInfo systemTypeInfo = null;
									string newName = frmAddSysType.NewName;
									if (sysTypeInfo.IsParent)
									{
										systemTypeInfo = new SystemTypeInfo
										{
											IsParent = true,
											SortIndex = sysTypeInfo.SortIndex + 1,
											SysType = newName
										};
										foreach (SystemTypeInfo systemTypeInfo2 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
										where x.IsParent && x.SortIndex > sysTypeInfo.SortIndex
										select x).ToList<SystemTypeInfo>()))
										{
											systemTypeInfo2.SortIndex++;
										}
										this.PipingTypeList.Add(systemTypeInfo);
										SystemTypeInfo systemTypeInfo3 = (from x in this.PipingTypeList
										where !x.IsParent && x.GroupName == sysTypeInfo.SysType
										orderby x.SortIndex
										select x).FirstOrDefault<SystemTypeInfo>();
										if (systemTypeInfo3 == null)
										{
											YJKMessageBox.Show("当前分组中无有效项！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
											return;
										}
										SystemTypeInfo systemTypeInfo4 = systemTypeInfo3.Clone();
										systemTypeInfo4.GroupName = newName;
										systemTypeInfo4.SortIndex = 0;
										IList<string> existNames2 = PipeSettingManager.GetExistNames(false, this.PipingTypeList);
										systemTypeInfo4.SysType = PipeSettingManager.GetUnifiedName(systemTypeInfo4.SysType + 1, existNames2);
										this.PipingTypeList.Add(systemTypeInfo4);
									}
									else
									{
										systemTypeInfo = sysTypeInfo.Clone();
										systemTypeInfo.SysType = newName;
										systemTypeInfo.SortIndex++;
										foreach (SystemTypeInfo systemTypeInfo5 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
										where !x.IsParent && x.GroupName == sysTypeInfo.GroupName && x.SortIndex > sysTypeInfo.SortIndex
										select x).ToList<SystemTypeInfo>()))
										{
											systemTypeInfo5.SortIndex++;
										}
										this.PipingTypeList.Add(systemTypeInfo);
									}
									this.RefreshTaskList();
									this.SelectedRow(systemTypeInfo);
								}
							}
						}
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("新建系统失败！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}

		private void btnDelSystem_Click(object sender, EventArgs e)
		{
			try
			{
				string message = "请选择删除项！";
				if (this.tvTaskList.SelectedRows.Count <= 0)
				{
					YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					TreeGridNode owningNode = ((TreeGridCell)this.tvTaskList.SelectedRows[0].Cells[0]).OwningNode;
					if (owningNode == null)
					{
						YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					}
					else
					{
						SystemTypeInfo curSysType = owningNode.Tag as SystemTypeInfo;
						if (curSysType == null)
						{
							YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						else if (this.IsLastNode(curSysType))
						{
							YJKMessageBox.Show("至少保留一条数据！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						else if (this.IsLastInClassifyGroup(curSysType))
						{
							YJKMessageBox.Show("每个系统分类的最后一个系统类型不能删除！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						else
						{
							IList<SystemTypeInfo> list = new List<SystemTypeInfo>();
							if (curSysType.IsParent)
							{
								list = (from x in this.PipingTypeList
								where !x.IsParent && x.GroupName == curSysType.SysType
								select x).ToList<SystemTypeInfo>();
							}
							else
							{
								list.Add(curSysType);
							}
							if (PipeSettingManager.IsExsitCreatedPiping(list))
							{
								YJKMessageBox.Show("选定的系统类型正在使用，因此不能修改系统名称或删除此系统！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
							}
							else
							{
								SystemTypeInfo systemTypeInfo = null;
								if (curSysType.IsParent)
								{
									this.PipingTypeList.RemoveAll((SystemTypeInfo x) => !x.IsParent && x.GroupName == curSysType.SysType);
									IList<SystemTypeInfo> list2 = (from x in this.PipingTypeList
									where x.IsParent && x.SortIndex > curSysType.SortIndex
									orderby x.SortIndex
									select x).ToList<SystemTypeInfo>();
									if (list2.Count <= 0)
									{
										systemTypeInfo = (from x in this.PipingTypeList
										where x.IsParent && x.SysType != curSysType.SysType
										orderby x.SortIndex
										select x).FirstOrDefault<SystemTypeInfo>();
									}
									else
									{
										systemTypeInfo = list2.First<SystemTypeInfo>();
									}
									IEnumerator<SystemTypeInfo> enumerator = list2.GetEnumerator();
									{
										while (enumerator.MoveNext())
										{
											SystemTypeInfo item = enumerator.Current;
											item.SortIndex--;
											foreach (SystemTypeInfo systemTypeInfo2 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
											where !x.IsParent && x.GroupName == item.SysType
											select x).ToList<SystemTypeInfo>()))
											{
												systemTypeInfo2.GroupSortIndex = item.SortIndex;
											}
										}
									}
									this.PipingTypeList.Remove(curSysType);
								}
								else if (((ICollection<SystemTypeInfo>)(from x in this.PipingTypeList
								where !x.IsParent && x.GroupName == curSysType.GroupName && x.SysType != curSysType.SysType
								select x).ToList<SystemTypeInfo>()).Count <= 0)
								{
									SystemTypeInfo parentNode = (from x in this.PipingTypeList
									where x.IsParent && x.SysType == curSysType.GroupName
									select x).FirstOrDefault<SystemTypeInfo>();
                                    IEnumerator<SystemTypeInfo> enumerator = ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
                                                                                                            where x.IsParent && x.SortIndex > parentNode.SortIndex
                                                                                                            orderby x.SortIndex
                                                                                                            select x).ToList<SystemTypeInfo>()).GetEnumerator();
									{
										while (enumerator.MoveNext())
										{
											SystemTypeInfo item = enumerator.Current;
											item.SortIndex--;
											foreach (SystemTypeInfo systemTypeInfo3 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
											where !x.IsParent && x.GroupName == item.SysType
											select x).ToList<SystemTypeInfo>()))
											{
												systemTypeInfo3.GroupSortIndex = item.SortIndex;
											}
										}
									}
									this.PipingTypeList.Remove(curSysType);
									this.PipingTypeList.Remove(parentNode);
								}
								else
								{
									IList<SystemTypeInfo> list3 = (from x in this.PipingTypeList
									where !x.IsParent && x.GroupName == curSysType.GroupName && x.SortIndex > curSysType.SortIndex
									orderby x.SortIndex
									select x).ToList<SystemTypeInfo>();
									IEnumerator<SystemTypeInfo> enumerator = list3.GetEnumerator();
									{
										while (enumerator.MoveNext())
										{
											SystemTypeInfo item = enumerator.Current;
											item.SortIndex--;
											foreach (SystemTypeInfo systemTypeInfo4 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
											where !x.IsParent && x.GroupName == item.SysType
											select x).ToList<SystemTypeInfo>()))
											{
												systemTypeInfo4.GroupSortIndex = item.SortIndex;
											}
										}
									}
									if (list3.Count <= 0)
									{
										systemTypeInfo = (from x in this.PipingTypeList
										where !x.IsParent && x.GroupName == curSysType.GroupName && x.SortIndex < curSysType.SortIndex
										orderby x.SortIndex
										select x).ToList<SystemTypeInfo>().FirstOrDefault<SystemTypeInfo>();
									}
									else
									{
										systemTypeInfo = list3.First<SystemTypeInfo>();
									}
									this.PipingTypeList.Remove(curSysType);
								}
								this.RefreshTaskList();
								if (systemTypeInfo != null)
								{
									this.SelectedRow(systemTypeInfo);
								}
							}
						}
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("删除系统失败!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}

		private bool IsLastNode(SystemTypeInfo sysType)
		{
			if (sysType == null)
			{
				throw new Exception("出现异常！");
			}
			if (sysType.IsParent)
			{
				if (((ICollection<SystemTypeInfo>)(from x in this.PipingTypeList
				where x.IsParent && x.SysType != sysType.SysType
				select x).ToList<SystemTypeInfo>()).Count <= 0)
				{
					return true;
				}
			}
			else if (((ICollection<SystemTypeInfo>)(from x in this.PipingTypeList
			where x.IsParent && x.SysType != sysType.GroupName
			select x).ToList<SystemTypeInfo>()).Count <= 0 && ((ICollection<SystemTypeInfo>)(from x in this.PipingTypeList
			where !x.IsParent && x.GroupName == sysType.GroupName && x.SysType != sysType.SysType
			select x).ToList<SystemTypeInfo>()).Count <= 0)
			{
				return true;
			}
			return false;
		}

		private void btnMoveUp_Click(object sender, EventArgs e)
		{
			if (this.tvTaskList.SelectedRows.Count <= 0)
			{
				YJKMessageBox.Show("请先选择移动项！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			TreeGridNode owningNode = ((TreeGridCell)this.tvTaskList.SelectedRows[0].Cells[0]).OwningNode;
			if (owningNode == null)
			{
				YJKMessageBox.Show("请先选择移动项！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			SystemTypeInfo prevNodeInfo = null;
			SystemTypeInfo currentRecord = owningNode.Tag as SystemTypeInfo;
			int curSortIndex = currentRecord.SortIndex;
			if (currentRecord.IsParent)
			{
				prevNodeInfo = (from x in this.PipingTypeList
				where x.IsParent && x.SortIndex < curSortIndex
				orderby x.SortIndex descending
				select x).FirstOrDefault<SystemTypeInfo>();
			}
			else
			{
				prevNodeInfo = (from x in this.PipingTypeList
				where !x.IsParent && x.GroupName == currentRecord.GroupName && x.SortIndex < curSortIndex
				orderby x.SortIndex descending
				select x).FirstOrDefault<SystemTypeInfo>();
			}
			if (prevNodeInfo == null)
			{
				return;
			}
			currentRecord.SortIndex = prevNodeInfo.SortIndex;
			prevNodeInfo.SortIndex = curSortIndex;
			if (currentRecord.IsParent)
			{
				foreach (SystemTypeInfo systemTypeInfo in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
				where !x.IsParent && x.GroupName == currentRecord.SysType
				select x).ToList<SystemTypeInfo>()))
				{
					systemTypeInfo.GroupSortIndex = currentRecord.SortIndex;
				}
				foreach (SystemTypeInfo systemTypeInfo2 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
				where !x.IsParent && x.GroupName == prevNodeInfo.SysType
				select x).ToList<SystemTypeInfo>()))
				{
					systemTypeInfo2.GroupSortIndex = prevNodeInfo.SortIndex;
				}
			}
			this.RefreshTaskList();
			this.SelectedRow(currentRecord);
		}

		private void btnMoveDown_Click(object sender, EventArgs e)
		{
			if (this.tvTaskList.SelectedRows.Count <= 0)
			{
				YJKMessageBox.Show("请先选择移动项！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			TreeGridNode owningNode = ((TreeGridCell)this.tvTaskList.SelectedRows[0].Cells[0]).OwningNode;
			if (owningNode == null)
			{
				YJKMessageBox.Show("请先选择移动项！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			SystemTypeInfo nextNodeInfo = null;
			SystemTypeInfo currentRecord = owningNode.Tag as SystemTypeInfo;
			int curSortIndex = currentRecord.SortIndex;
			if (currentRecord.IsParent)
			{
				nextNodeInfo = (from x in this.PipingTypeList
				where x.IsParent && x.SortIndex > curSortIndex
				orderby x.SortIndex
				select x).FirstOrDefault<SystemTypeInfo>();
			}
			else
			{
				nextNodeInfo = (from x in this.PipingTypeList
				where x.GroupName == currentRecord.GroupName && x.SortIndex > curSortIndex
				orderby x.SortIndex
				select x).FirstOrDefault<SystemTypeInfo>();
			}
			if (nextNodeInfo == null)
			{
				return;
			}
			currentRecord.SortIndex = nextNodeInfo.SortIndex;
			nextNodeInfo.SortIndex = curSortIndex;
			if (currentRecord.IsParent)
			{
				foreach (SystemTypeInfo systemTypeInfo in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
				where !x.IsParent && x.GroupName == currentRecord.SysType
				select x).ToList<SystemTypeInfo>()))
				{
					systemTypeInfo.GroupSortIndex = currentRecord.SortIndex;
				}
				foreach (SystemTypeInfo systemTypeInfo2 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
				where !x.IsParent && x.GroupName == nextNodeInfo.SysType
				select x).ToList<SystemTypeInfo>()))
				{
					systemTypeInfo2.GroupSortIndex = nextNodeInfo.SortIndex;
				}
			}
			this.RefreshTaskList();
			this.SelectedRow(currentRecord);
		}

		private void btnHyStd_Click(object sender, EventArgs e)
		{
			FrmHYStandard frmHYStandard = new FrmHYStandard();
			if (frmHYStandard.ShowDialog() != DialogResult.OK)
			{
				return;
			}
			IDictionary<string, IList<SystemTypeInfo>> hyPipingStyle = frmHYStandard.HyPipingStyle;
			if (hyPipingStyle.Count <= 0)
			{
				return;
			}
			IList<string> list = (from x in this.PipingTypeList
			where x.IsParent
			select x.SysType).ToList<string>();
			IDictionary<SystemTypeInfo, IList<SystemTypeInfo>> dictionary = new Dictionary<SystemTypeInfo, IList<SystemTypeInfo>>();
			IList<SystemTypeInfo> list2 = new List<SystemTypeInfo>();
			IEnumerator<string> enumerator = hyPipingStyle.Keys.GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					string key = enumerator.Current;
					int num = -1;
					IList<SystemTypeInfo> list3 = hyPipingStyle[key];
					if (list.Contains(key))
					{
						IList<SystemTypeInfo> list4 = new List<SystemTypeInfo>();
						SystemTypeInfo key2 = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => x.IsParent && x.SysType == key);
						IEnumerator<SystemTypeInfo> enumerator2 = list3.GetEnumerator();
						{
							while (enumerator2.MoveNext())
							{
								SystemTypeInfo item = enumerator2.Current;
								SystemTypeInfo systemTypeInfo = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => !x.IsParent && x.SysType == item.SysType);
								if (systemTypeInfo == null)
								{
									int sortIndex = (from x in this.PipingTypeList
									where !x.IsParent && x.GroupName == item.GroupName
									select x).Count<SystemTypeInfo>();
									item.SortIndex = sortIndex;
									item.GroupSortIndex = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => !x.IsParent && x.GroupName == item.GroupName).GroupSortIndex;
									this.PipingTypeList.Add(item);
								}
								else
								{
									if (systemTypeInfo.SysCategory != item.SysCategory)
									{
										if (this.IsLastInClassifyGroup(systemTypeInfo))
										{
											list2.Add(systemTypeInfo);
											continue;
										}
										if (PipeSettingManager.IsExsitCreatedPiping(new List<SystemTypeInfo>
										{
											systemTypeInfo
										}))
										{
											list2.Add(systemTypeInfo);
											continue;
										}
									}
									if (systemTypeInfo.GroupName != item.GroupName)
									{
										if (num == -1)
										{
											num = (from x in this.PipingTypeList
											where !x.IsParent && x.GroupName == item.GroupName
											select x).Count<SystemTypeInfo>();
										}
										item.SortIndex = num++;
										item.GroupSortIndex = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => !x.IsParent && x.GroupName == item.GroupName).GroupSortIndex;
									}
									else
									{
										item.SortIndex = systemTypeInfo.SortIndex;
										item.GroupSortIndex = systemTypeInfo.GroupSortIndex;
									}
									list4.Add(item);
								}
							}
						}
						if (list4.Count > 0)
						{
							dictionary.Add(key2, list4);
						}
					}
					else
					{
						IList<SystemTypeInfo> list5 = new List<SystemTypeInfo>();
						int sortIndex2 = (from x in this.PipingTypeList
						where x.IsParent
						select x).Count<SystemTypeInfo>();
						SystemTypeInfo systemTypeInfo2 = new SystemTypeInfo
						{
							IsParent = true,
							SortIndex = sortIndex2,
							SysType = key
						};
						int num2 = 0;
						IEnumerator<SystemTypeInfo> enumerator2 = list3.GetEnumerator();
						{
							while (enumerator2.MoveNext())
							{
								SystemTypeInfo item = enumerator2.Current;
								item.GroupName = key;
								item.SortIndex = num2++;
								item.GroupSortIndex = systemTypeInfo2.SortIndex;
								SystemTypeInfo systemTypeInfo3 = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => !x.IsParent && x.SysType == item.SysType);
								if (systemTypeInfo3 == null)
								{
									this.PipingTypeList.Add(item);
									if (!this.PipingTypeList.Contains(systemTypeInfo2))
									{
										this.PipingTypeList.Add(systemTypeInfo2);
									}
								}
								else if (systemTypeInfo3.SysCategory != item.SysCategory)
								{
									if (!this.IsLastInClassifyGroup(systemTypeInfo3))
									{
										if (PipeSettingManager.IsExsitCreatedPiping(new List<SystemTypeInfo>
										{
											systemTypeInfo3
										}))
										{
											list2.Add(systemTypeInfo3);
										}
										else
										{
											list5.Add(item);
										}
									}
								}
								else
								{
									list5.Add(item);
								}
							}
						}
						if (list5.Count > 0)
						{
							dictionary.Add(systemTypeInfo2, list5);
						}
					}
				}
			}
            if ((dictionary.Count<KeyValuePair<SystemTypeInfo, IList<SystemTypeInfo>>>() > 0 || list2.Count > 0) && YJKMessageBox.Show("导入的系统类型与当前项目中系统类型名称冲突，是否替换当前项目中系统类型的设置。", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
            }
            //{
            //    FrmPipeSetting.<>c__DisplayClass15_3 <>c__DisplayClass15_4 = new FrmPipeSetting.<>c__DisplayClass15_3();
            //    <>c__DisplayClass15_4.tmpItem = null;
            //    <>c__DisplayClass15_4.groupItem = null;
            //    foreach (SystemTypeInfo systemTypeInfo4 in dictionary.Keys)
            //    {
            //        if (!this.PipingTypeList.Contains(systemTypeInfo4))
            //        {
            //            this.PipingTypeList.Add(systemTypeInfo4);
            //        }
            //        IEnumerator<SystemTypeInfo> enumerator3 = dictionary[systemTypeInfo4].GetEnumerator();
            //        {
            //            while (enumerator3.MoveNext())
            //            {
            //                SystemTypeInfo item = enumerator3.Current;
            //                <>c__DisplayClass15_4.tmpItem = (from x in this.PipingTypeList
            //                where x.SysType == item.SysType && !x.IsParent
            //                select x).FirstOrDefault<SystemTypeInfo>();
            //                if (<>c__DisplayClass15_4.tmpItem != null)
            //                {
            //                    this.PipingTypeList.Remove(<>c__DisplayClass15_4.tmpItem);
            //                    this.PipingTypeList.Add(item);
            //                    IEnumerable<SystemTypeInfo> pipingTypeList = this.PipingTypeList;
            //                    Func<SystemTypeInfo, bool> predicate;
            //                    if ((predicate = <>c__DisplayClass15_4.<>9__11) == null)
            //                    {
            //                        predicate = (<>c__DisplayClass15_4.<>9__11 = ((SystemTypeInfo x) => !x.IsParent && x.GroupName == <>c__DisplayClass15_4.tmpItem.GroupName));
            //                    }
            //                    if (pipingTypeList.Where(predicate).Count<SystemTypeInfo>() <= 0)
            //                    {
            //                        FrmPipeSetting.<>c__DisplayClass15_3 <>c__DisplayClass15_6 = <>c__DisplayClass15_4;
            //                        IEnumerable<SystemTypeInfo> pipingTypeList2 = this.PipingTypeList;
            //                        Func<SystemTypeInfo, bool> predicate2;
            //                        if ((predicate2 = <>c__DisplayClass15_4.<>9__12) == null)
            //                        {
            //                            predicate2 = (<>c__DisplayClass15_4.<>9__12 = ((SystemTypeInfo x) => x.IsParent && x.SysType == <>c__DisplayClass15_4.tmpItem.GroupName));
            //                        }
            //                        <>c__DisplayClass15_6.groupItem = pipingTypeList2.FirstOrDefault(predicate2);
            //                        this.PipingTypeList.Remove(<>c__DisplayClass15_4.groupItem);
            //                        IEnumerable<SystemTypeInfo> pipingTypeList3 = this.PipingTypeList;
            //                        Func<SystemTypeInfo, bool> predicate3;
            //                        if ((predicate3 = <>c__DisplayClass15_4.<>9__13) == null)
            //                        {
            //                            predicate3 = (<>c__DisplayClass15_4.<>9__13 = ((SystemTypeInfo x) => x.IsParent && x.SortIndex > <>c__DisplayClass15_4.groupItem.SortIndex));
            //                        }
            //                        IEnumerator<SystemTypeInfo> enumerator4 = ((IEnumerable<SystemTypeInfo>)pipingTypeList3.Where(predicate3).ToList<SystemTypeInfo>()).GetEnumerator();
            //                        {
            //                            while (enumerator4.MoveNext())
            //                            {
            //                                SystemTypeInfo gItem = enumerator4.Current;
            //                                gItem.SortIndex--;
            //                                foreach (SystemTypeInfo systemTypeInfo5 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
            //                                where !x.IsParent && x.GroupName == gItem.SysType
            //                                select x).ToList<SystemTypeInfo>()))
            //                                {
            //                                    systemTypeInfo5.GroupSortIndex = gItem.SortIndex;
            //                                }
            //                            }
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //    }
            //    if (list2.Count > 0)
            //    {
            //        StringBuilder stringBuilder = new StringBuilder();
            //        stringBuilder.Append("[");
            //        foreach (SystemTypeInfo systemTypeInfo6 in list2)
            //        {
            //            stringBuilder.Append(systemTypeInfo6.SysType);
            //            stringBuilder.Append(",");
            //        }
            //        stringBuilder.Append("]");
            //        stringBuilder.Remove(stringBuilder.Length - 2, 1);
            //        YJKMessageBox.Show(string.Format("选定的系统类型{0}正在使用，因此不能修改系统名称或删除此系统！", stringBuilder.ToString()), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //    }
            //}
			this.RefreshTaskList();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.EmptyCellCheck())
			{
				YJKMessageBox.Show("系统类型名称不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void btnPipeMaterialBase_Click(object sender, EventArgs e)
		{
			try
			{
				new FrmPipeMaterial().ShowDialog();
			}
			catch (Exception ex)
			{
				YJKMessageBox.Show(ex.Message);
			}
		}

		private void tvTaskList_DataError(object sender, DataGridViewDataErrorEventArgs e)
		{
		}



		private void tvTaskList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
			if (this.isInit)
			{
				return;
			}
			int columnIndex = e.ColumnIndex;
			int rowIndex = e.RowIndex;
			TreeGridNode nodeForRow = this.tvTaskList.GetNodeForRow(rowIndex);
			string text = (nodeForRow.Cells[columnIndex].Value == null) ? null : nodeForRow.Cells[columnIndex].Value.ToString().Trim();
			SystemTypeInfo systemTypeInfo = nodeForRow.Tag as SystemTypeInfo;
			string name = nodeForRow.Cells[columnIndex].OwningColumn.Name;
            uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
			if (num <= 2005745351u)
			{
				if (num <= 1495856670u)
				{
					if (num != 1463138041u)
					{
						if (num != 1495856670u)
						{
							return;
						}
						if (!(name == "colPipingCategory"))
						{
							return;
						}
						systemTypeInfo.SysCategory = text;
						return;
					}
					else
					{
						if (!(name == "colPipingGroup"))
						{
							return;
						}
						if (systemTypeInfo.GroupName != text)
						{
							string groupName = systemTypeInfo.GroupName;
							int sortIndex = systemTypeInfo.SortIndex;
							this.UpdateGroupName(text, systemTypeInfo);
							this.RemoveEmptyGroup(groupName, sortIndex);
							this.RefreshTaskList();
							this.SelectedRow(systemTypeInfo);
						}
						return;
					}
				}
				else if (num != 1996446426u)
				{
					if (num != 2005745351u)
					{
						return;
					}
					if (!(name == "colLineWeight"))
					{
						return;
					}
					systemTypeInfo.LineWeight = text;
					return;
				}
				else
				{
					if (!(name == "colSysType"))
					{
						return;
					}
					IList<string> existNames = PipeSettingManager.GetExistNames(systemTypeInfo.IsParent, this.PipingTypeList);
					existNames.Remove(systemTypeInfo.SysType);
					if (existNames.Contains(text))
					{
						YJKMessageBox.Show("不能修改，已存在相同名称的系统类型!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						this.isInit = true;
						nodeForRow.Cells[e.ColumnIndex].SetValue(systemTypeInfo.SysType);
						this.isInit = false;
						this.SelectedRow(systemTypeInfo);
						return;
					}
					if (PipeSettingManager.IsExsitCreatedPiping(new List<SystemTypeInfo>
					{
						systemTypeInfo
					}))
					{
						YJKMessageBox.Show("选定的系统类型正在使用，因此不能修改系统名称或删除此系统！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						this.isInit = true;
						nodeForRow.Cells[e.ColumnIndex].SetValue(systemTypeInfo.SysType);
						this.isInit = false;
						this.SelectedRow(systemTypeInfo);
						return;
					}
					systemTypeInfo.SysType = text;
					return;
				}
			}
			else if (num <= 2971373733u)
			{
				if (num != 2835151868u)
				{
					if (num != 2971373733u)
					{
						return;
					}
					if (!(name == "colPipeType"))
					{
						return;
					}
					systemTypeInfo.PipeType = text;
					return;
				}
				else
				{
					if (!(name == "colAbb"))
					{
						return;
					}
					systemTypeInfo.Abbreviation = text;
					return;
				}
			}
			else if (num != 3786413770u)
			{
				if (num != 3800690131u)
				{
					return;
				}
				if (!(name == "colLinePattern"))
				{
					return;
				}
				systemTypeInfo.LinePattern = text;
				return;
			}
			else
			{
				if (!(name == "colLineColor"))
				{
					return;
				}
				systemTypeInfo.LineColor = text;
				return;
			}
		}

		private void RemoveEmptyGroup(string oldGroupName, int oldSortIndex)
		{
			if (string.IsNullOrEmpty(oldGroupName))
			{
				return;
			}
			if ((from x in this.PipingTypeList
			where !x.IsParent && x.GroupName == oldGroupName
			select x).Count<SystemTypeInfo>() <= 0)
			{
				SystemTypeInfo emptyGroup = this.PipingTypeList.FirstOrDefault((SystemTypeInfo x) => x.IsParent && x.SysType == oldGroupName);
				this.PipingTypeList.Remove(emptyGroup);
                IEnumerator<SystemTypeInfo> enumerator = ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
                                                                                        where x.IsParent && x.SortIndex > emptyGroup.SortIndex
                                                                                        orderby x.SortIndex
                                                                                        select x).ToList<SystemTypeInfo>()).GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						SystemTypeInfo systemTypeInfo = enumerator.Current;
						systemTypeInfo.SortIndex--;
					}
					return;
				}
			}
			foreach (SystemTypeInfo systemTypeInfo2 in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
			where !x.IsParent && x.GroupName == oldGroupName && x.SortIndex > oldSortIndex
			orderby x.SortIndex
			select x).ToList<SystemTypeInfo>()))
			{
				systemTypeInfo2.SortIndex--;
			}
		}

		private void UpdateGroupName(string changedValue, SystemTypeInfo sysTypeInfo)
		{
			if (sysTypeInfo == null)
			{
				return;
			}
			SystemTypeInfo systemTypeInfo = (from x in this.PipingTypeList
			where !x.IsParent && x.GroupName == changedValue
			orderby x.SortIndex descending
			select x).FirstOrDefault<SystemTypeInfo>();
			if (systemTypeInfo == null)
			{
				SystemTypeInfo systemTypeInfo2 = new SystemTypeInfo();
				systemTypeInfo2.SysType = changedValue;
				systemTypeInfo2.IsParent = true;
				SystemTypeInfo systemTypeInfo3 = (from x in this.PipingTypeList
				where x.IsParent
				orderby x.SortIndex descending
				select x).FirstOrDefault<SystemTypeInfo>();
				systemTypeInfo2.SortIndex = ((systemTypeInfo3 == null) ? 0 : (systemTypeInfo3.SortIndex + 1));
				this.PipingTypeList.Add(systemTypeInfo2);
				sysTypeInfo.GroupName = changedValue;
				sysTypeInfo.SortIndex = 0;
				return;
			}
			int sortIndex = systemTypeInfo.SortIndex;
			sysTypeInfo.SortIndex = sortIndex + 1;
			sysTypeInfo.GroupName = changedValue;
		}

		private void tvTaskList_SelectionChanged(object sender, EventArgs e)
		{
			if (this.isInit)
			{
				return;
			}
			if (this.tvTaskList.SelectedRows.Count <= 0)
			{
				return;
			}
			TreeGridNode owningNode = ((TreeGridCell)this.tvTaskList.SelectedRows[0].Cells[0]).OwningNode;
			if (owningNode == null)
			{
				return;
			}
			this.btnMoveUp.Enabled = !owningNode.IsFirstSibling;
			this.btnMoveDown.Enabled = !owningNode.IsLastSibling;
		}

		private void SelectedRow(SystemTypeInfo selectedItem)
		{
			if (selectedItem == null)
			{
				return;
			}
			bool flag = false;
			TreeGridNode treeGridNode = null;
			this.tvTaskList.ClearSelection();
			foreach (TreeGridNode treeGridNode2 in this.tvTaskList.Nodes)
			{
				if (treeGridNode2.Tag as SystemTypeInfo == selectedItem)
				{
					int rowIndex = treeGridNode2.RowIndex;
					treeGridNode = treeGridNode2;
					treeGridNode2.Selected = true;
					while (!treeGridNode2.Selected)
					{
						treeGridNode2.Selected = true;
					}
					flag = true;
					break;
				}
				if (treeGridNode2.HasChildren)
				{
					foreach (TreeGridNode treeGridNode3 in treeGridNode2.Nodes)
					{
						if (treeGridNode3.Tag as SystemTypeInfo == selectedItem)
						{
							treeGridNode2.Expand();
							treeGridNode = treeGridNode3;
							int rowIndex2 = treeGridNode3.RowIndex;
							treeGridNode3.Selected = true;
							while (!treeGridNode3.Selected)
							{
								treeGridNode3.Selected = true;
							}
							flag = true;
							break;
						}
					}
					if (flag)
					{
						break;
					}
				}
			}
			if (treeGridNode != null)
			{
				this.tvTaskList.CurrentCell = treeGridNode.Cells[0];
			}
		}

		private void RefreshTaskList()
		{
			this.isInit = true;
			this.FillFormInfo();
			this.isInit = false;
		}

		private void FillFormInfo()
		{
			this.tvTaskList.Nodes.Clear();
			if (this.PipingTypeList == null || this.PipingTypeList.Count <= 0)
			{
				return;
			}
			System.Drawing.Color foreColor = System.Drawing.Color.Empty;
			Font font = new Font(this.tvTaskList.DefaultCellStyle.Font, FontStyle.Bold);
			List<SystemTypeInfo> list = (from x in this.PipingTypeList
			where x.IsParent
			orderby x.SortIndex
			select x).ToList<SystemTypeInfo>();
			IList<string> list2 = (from x in list
			select x.SysType).ToList<string>();
			PipeSettingManager.AddSourceGroups(list2);
			this.InitComboBoxColumn(this.colPipingGroup, list2);
			IEnumerator<SystemTypeInfo> enumerator = ((IEnumerable<SystemTypeInfo>)list).GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					SystemTypeInfo groupNode = enumerator.Current;
					TreeGridNode treeGridNode = this.tvTaskList.Nodes.Add(groupNode.SysType);
					treeGridNode.DefaultCellStyle.Font = font;
					treeGridNode.Tag = groupNode;
					treeGridNode.ReadOnly = true;
					treeGridNode.Height = 20;
					treeGridNode.Expand();
					for (int i = 1; i < this.tvTaskList.ColumnCount; i++)
					{
						DataGridViewTextBoxCell value = new DataGridViewTextBoxCell();
						treeGridNode.Cells[i] = value;
					}
					foreach (SystemTypeInfo systemTypeInfo in ((IEnumerable<SystemTypeInfo>)(from x in this.PipingTypeList
					where x.GroupName == groupNode.SysType && !x.IsParent
					orderby x.SortIndex
					select x).ToList<SystemTypeInfo>()))
					{
						TreeGridNode treeGridNode2 = treeGridNode.Nodes.Add(new object[]
						{
							systemTypeInfo.SysType,
							systemTypeInfo.Abbreviation,
							systemTypeInfo.PipeType,
							systemTypeInfo.LineColor,
							systemTypeInfo.LinePattern,
							systemTypeInfo.LineWeight,
							systemTypeInfo.SysCategory,
							systemTypeInfo.GroupName
						});
						treeGridNode2.Tag = systemTypeInfo;
						treeGridNode2.Height = 20;
						foreColor = SystemManageHelper.getXMLDataColor(systemTypeInfo.LineColor);
						treeGridNode2.Cells["colLineColor"].Style.ForeColor = foreColor;
						treeGridNode2.Cells["colPipingCategory"].Style.BackColor = System.Drawing.Color.LightGray;
					}
				}
			}
		}

		private void SetPropertys(DataGridViewColumn column, string name, string headerText, int width, string dataPropertyName)
		{
			column.Name = name;
			column.HeaderText = headerText;
			column.Width = width;
			column.DataPropertyName = dataPropertyName;
		}

		private void CreateColumnHeader(IList<string> groupNameList, bool isGroupName = false)
		{
			this.tvTaskList.Columns.Clear();
			if (isGroupName)
			{
				TreeGridColumn treeGridColumn = new TreeGridColumn();
				this.SetPropertys(treeGridColumn, "colSysType", "系统类型", 80, "SysType");
				this.tvTaskList.Columns.Add(treeGridColumn);
				DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
				this.SetPropertys(dataGridViewTextBoxColumn, "colAbb", "缩写", 80, "Abbreviation");
				this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn);
				DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
				this.SetPropertys(dataGridViewTextBoxColumn2, "colPipeMaterial", "管材", 80, "PipeMaterial");
				this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn2);
				DataGridViewTextBoxColumn dataGridViewTextBoxColumn3 = new DataGridViewTextBoxColumn();
				this.SetPropertys(dataGridViewTextBoxColumn3, "colConnStyle", "连接方式", 80, "ConnStyle");
				this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn3);
				DataGridViewTextBoxColumn dataGridViewTextBoxColumn4 = new DataGridViewTextBoxColumn();
				this.SetPropertys(dataGridViewTextBoxColumn4, "colLineColor", "线颜色", 80, "LineColor");
				this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn4);
				DataGridViewTextBoxColumn dataGridViewTextBoxColumn5 = new DataGridViewTextBoxColumn();
				this.SetPropertys(dataGridViewTextBoxColumn5, "colLineWeight", "线宽", 80, "LineWeight");
				this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn5);
				DataGridViewTextBoxColumn dataGridViewTextBoxColumn6 = new DataGridViewTextBoxColumn();
				this.SetPropertys(dataGridViewTextBoxColumn6, "colLinePattern", "线型", 80, "LinePattern");
				this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn6);
				DataGridViewTextBoxColumn dataGridViewTextBoxColumn7 = new DataGridViewTextBoxColumn();
				this.SetPropertys(dataGridViewTextBoxColumn7, "colGroupName", "系统组名", 80, "GroupSysType");
				this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn7);
				DataGridViewTextBoxColumn dataGridViewTextBoxColumn8 = new DataGridViewTextBoxColumn();
				this.SetPropertys(dataGridViewTextBoxColumn8, "colSysCategory", "系统分类", 80, "SysCategory");
				this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn8);
				return;
			}
			IList<string> linePatternName = PipeSettingManager.GetLinePatternName();
			IEnumerable<string> lineWeight = PipeSettingManager.GetLineWeight();
			TreeGridColumn treeGridColumn2 = new TreeGridColumn();
			this.SetPropertys(treeGridColumn2, "colSysType", "系统类型", 80, "SysType");
			this.tvTaskList.Columns.Add(treeGridColumn2);
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn9 = new DataGridViewTextBoxColumn();
			this.SetPropertys(dataGridViewTextBoxColumn9, "colAbb", "缩写", 80, "Abbreviation");
			this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn9);
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn = new DataGridViewComboBoxColumn();
			this.SetPropertys(dataGridViewComboBoxColumn, "colPipeMaterial", "管材", 80, "PipeMaterial");
			this.tvTaskList.Columns.Add(dataGridViewComboBoxColumn);
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn2 = new DataGridViewComboBoxColumn();
			this.SetPropertys(dataGridViewComboBoxColumn2, "colConnStyle", "连接方式", 80, "ConnStyle");
			this.tvTaskList.Columns.Add(dataGridViewComboBoxColumn2);
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn10 = new DataGridViewTextBoxColumn();
			this.SetPropertys(dataGridViewTextBoxColumn10, "colLineColor", "线颜色", 80, "LineColor");
			this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn10);
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn3 = new DataGridViewComboBoxColumn();
			this.SetPropertys(dataGridViewComboBoxColumn3, "colLineWeight", "线宽", 80, "LineWeight");
			this.tvTaskList.Columns.Add(dataGridViewComboBoxColumn3);
			foreach (string text in lineWeight)
			{
				dataGridViewComboBoxColumn3.Items.Add(text.ToString());
			}
			dataGridViewComboBoxColumn3.Items.Add("默认");
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn4 = new DataGridViewComboBoxColumn();
			this.SetPropertys(dataGridViewComboBoxColumn4, "colLinePattern", "线型", 80, "LinePattern");
			this.tvTaskList.Columns.Add(dataGridViewComboBoxColumn4);
			foreach (string item in linePatternName)
			{
				dataGridViewComboBoxColumn4.Items.Add(item);
			}
			dataGridViewComboBoxColumn4.Items.Add("默认");
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn5 = new DataGridViewComboBoxColumn();
			this.SetPropertys(dataGridViewComboBoxColumn5, "colGroupName", "系统组名", 80, "GroupSysType");
			this.tvTaskList.Columns.Add(dataGridViewComboBoxColumn5);
			foreach (string item2 in groupNameList)
			{
				dataGridViewComboBoxColumn5.Items.Add(item2);
			}
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn11 = new DataGridViewTextBoxColumn();
			this.SetPropertys(dataGridViewTextBoxColumn11, "colSysCategory", "系统分类", 80, "SysCategory");
			this.tvTaskList.Columns.Add(dataGridViewTextBoxColumn11);
		}

		private void SaveFileDialog(string fileName)
		{
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.Filter = " xml files(*.xml)|*.xml|All files(*.*)|*.*";
			saveFileDialog.FileName = fileName;
			saveFileDialog.FilterIndex = 1;
			saveFileDialog.RestoreDirectory = true;
			if (saveFileDialog.ShowDialog() == DialogResult.OK)
			{
				string fileName2 = saveFileDialog.FileName;
				IDictionary<SystemTypeInfo, IList<SystemTypeInfo>> dictionary = PipeSettingManager.GroupAndSort(this.PipingTypeList);
				if (dictionary == null)
				{
					return;
				}
				string empty = string.Empty;
				XmlElement xmlElement = null;
				XmlElement xmlElement2 = null;
				SystemTypeXmlHelper systemTypeXmlHelper = new SystemTypeXmlHelper();
				XmlDeclaration newChild = systemTypeXmlHelper.CreateDeclaration();
				systemTypeXmlHelper.XmlDoc.AppendChild(newChild);
				XmlElement xmlElement3 = systemTypeXmlHelper.CreateNode("pipingSystemTypeManage");
				systemTypeXmlHelper.XmlDoc.AppendChild(xmlElement3);
				XmlElement xmlElement4 = systemTypeXmlHelper.CreateNode("styleNode", new Hashtable
				{
					{
						"name",
						"当前项目"
					}
				});
				xmlElement3.AppendChild(xmlElement4);
				xmlElement = systemTypeXmlHelper.CreateNode("system", new Hashtable
				{
					{
						"name",
						PipeSettingManager.SystemName
					}
				});
				xmlElement4.AppendChild(xmlElement);
				foreach (SystemTypeInfo systemTypeInfo in dictionary.Keys)
				{
					IEnumerable<SystemTypeInfo> enumerable = dictionary[systemTypeInfo];
					xmlElement2 = systemTypeXmlHelper.CreateNode("group", new Hashtable
					{
						{
							"name",
							systemTypeInfo.SysType
						}
					});
					foreach (SystemTypeInfo systemTypeInfo2 in enumerable)
					{
						XmlElement newChild2 = systemTypeXmlHelper.CreateNode("add", new Hashtable
						{
							{
								"pipingSystemType",
								systemTypeInfo2.SysType
							},
							{
								"pipingSystemTypeAbb",
								systemTypeInfo2.Abbreviation
							},
							{
								"pipeType",
								systemTypeInfo2.PipeType
							},
							{
								"lineColor",
								systemTypeInfo2.LineColor
							},
							{
								"linePattern",
								systemTypeInfo2.LinePattern
							},
							{
								"lineWeight",
								systemTypeInfo2.LineWeight
							},
							{
								"pipingClassify",
								systemTypeInfo2.SysCategory
							}
						});
						xmlElement2.AppendChild(newChild2);
					}
					xmlElement.AppendChild(xmlElement2);
				}
				systemTypeXmlHelper.Save(fileName2);
				YJKMessageBox.Show("导出标准成功！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}

		private void InitComboBoxColumn(DataGridViewComboBoxColumn column, IList<string> dataList)
		{
			int num = 0;
			string text = "";
			column.Items.Clear();
			if (dataList == null)
			{
				return;
			}
			foreach (string text2 in dataList)
			{
				if (text2.Length > num)
				{
					num = text2.Length;
					text = text2;
				}
				column.Items.Add(text2);
			}
			int dropDownWidth = DataGridViewCell.MeasureTextWidth(base.CreateGraphics(), text, this.Font, 50, TextFormatFlags.Default);
			column.DropDownWidth = dropDownWidth;
		}

		private void SetGridStyle()
		{
		}

		private void tvTaskList_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
		{
			if (this.isInit)
			{
				return;
			}
			int columnIndex = e.ColumnIndex;
			int rowIndex = e.RowIndex;
			TreeGridNode nodeForRow = this.tvTaskList.GetNodeForRow(rowIndex);
			if (nodeForRow.Cells[columnIndex].OwningColumn.Name != "colLineColor")
			{
				return;
			}
			string colorStr = (nodeForRow.Cells[columnIndex].Value == null) ? null : nodeForRow.Cells[columnIndex].Value.ToString();
			this.ShowColorDialog(colorStr, nodeForRow, columnIndex);
			e.Cancel = true;
		}

		private void ShowColorDialog(string colorStr, TreeGridNode treeGridNode, int columnIndex)
		{
			ColorDialog colorDialog = new ColorDialog();
			colorDialog.AllowFullOpen = true;
			colorDialog.FullOpen = true;
			System.Drawing.Color xmldataColor = SystemManageHelper.getXMLDataColor(colorStr);
			if (!xmldataColor.IsKnownColor)
			{
				int[] array = new int[16];
				array[0] = SystemManageHelper.GetIntAboutColor(xmldataColor);
				colorDialog.CustomColors = array;
			}
			colorDialog.Color = xmldataColor;
			DialogResult dialogResult = colorDialog.ShowDialog();
			if (DialogResult.OK == dialogResult)
			{
				string newRGB = SystemManageHelper.getNewRGB(colorDialog.Color.R);
				string newRGB2 = SystemManageHelper.getNewRGB(colorDialog.Color.G);
				string newRGB3 = SystemManageHelper.getNewRGB(colorDialog.Color.B);
				string str = string.Concat(new string[]
				{
					"RGB ",
					newRGB.ToString(),
					" ",
					newRGB2.ToString(),
					" ",
					newRGB3.ToString()
				});
				string text = "█" + str;
				treeGridNode.Cells[columnIndex].SetValue(text);
				System.Drawing.Color xmldataColor2 = SystemManageHelper.getXMLDataColor(text);
				treeGridNode.Cells[columnIndex].Style.ForeColor = xmldataColor2;
			}
		}

		private void tvTaskList_MouseWheel(object sender, MouseEventArgs e)
		{
		}

		private bool IsLastInClassifyGroup(SystemTypeInfo input)
		{
			if (input == null)
			{
				throw new Exception("判断当前数据所在分类下是否是最后一条数据时，参数传递出错!");
			}
			bool result = false;
			if (input.IsParent)
			{
                IEnumerator<IGrouping<string, SystemTypeInfo>> enumerator = (from x in this.PipingTypeList
                                                                             where !x.IsParent && x.GroupName == input.SysType
                                                                             group x by x.SysCategory).GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						IGrouping<string, SystemTypeInfo> item = enumerator.Current;
						if ((from x in this.PipingTypeList
						where !x.IsParent && x.SysCategory == item.Key && x.GroupName != input.SysType
						select x).Count<SystemTypeInfo>() <= 0)
						{
							result = true;
							break;
						}
					}
					return result;
				}
			}
			if ((from x in this.PipingTypeList
			where !x.IsParent && x.SysCategory == input.SysCategory
			select x).Count<SystemTypeInfo>() <= 1)
			{
				result = true;
			}
			return result;
		}

		private bool EmptyCellCheck()
		{
			bool flag = false;
			foreach (TreeGridNode treeGridNode in this.tvTaskList.Nodes)
			{
				foreach (TreeGridNode treeGridNode2 in treeGridNode.Nodes)
				{
					DataGridViewCell dataGridViewCell = treeGridNode2.Cells[0];
					if (dataGridViewCell.Value == null)
					{
						flag = true;
						this.tvTaskList.ClearSelection();
						treeGridNode2.Selected = true;
						this.tvTaskList.CurrentCell = dataGridViewCell;
						break;
					}
				}
				if (flag)
				{
					break;
				}
			}
			return flag;
		}

		private void FrmPipeSetting_FormClosing(object sender, FormClosingEventArgs e)
		{
			try
			{
				string[] settings = new string[]
				{
					base.Width.ToString(),
					base.Height.ToString(),
					this.colSysType.Width.ToString(),
					this.colAbb.Width.ToString(),
					this.colPipeType.Width.ToString(),
					this.colLineColor.Width.ToString(),
					this.colLinePattern.Width.ToString(),
					this.colLineWeight.Width.ToString(),
					this.colPipingCategory.Width.ToString(),
					this.colPipingGroup.Width.ToString()
				};
				this.userSettingMgr.WritePipeSettingInfo(settings);
			}
			catch (Exception ex)
			{
				string message = ex.Message;
			}
		}

		private bool isInit;

		public List<SystemTypeInfo> PipingTypeList;

		private HVACUserSetting userSettingMgr = new HVACUserSetting();
	}
}
